package com.gome.ocean.service.datax.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.gome.ocean.dao.datax.DataSourceOAAuthApplyDAO;
import com.gome.ocean.dao.model.datasource.DataSourceAuthorityOAApplyBean;
import com.gome.ocean.service.datax.IDataSourceAuthApplyService;
import com.google.common.collect.Lists;

/**
 * @author zhangguoqing 2016年10月19日 下午2:48:36
 * @since 5.0.0
 */
@Service("dataSourceAuthApplyServiceImpl")
public class DataSourceAuthApplyServiceImpl implements IDataSourceAuthApplyService {

    @Autowired
    private DataSourceOAAuthApplyDAO dataSourceAuthDao;

    @Override
    public boolean insert(DataSourceAuthorityOAApplyBean applyBean) {
        try {
            dataSourceAuthDao.insert(applyBean);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean updateById(DataSourceAuthorityOAApplyBean applyBean) {
        try {
            dataSourceAuthDao.updateById(applyBean);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public DataSourceAuthorityOAApplyBean getBeanByMap(Map<String, Object> map) {
        try {
            DataSourceAuthorityOAApplyBean data = dataSourceAuthDao.getBeanByMap(map);
            return data;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<DataSourceAuthorityOAApplyBean> getBeanListsByMap(Map<String, Object> map, Integer pageNum,
                                                                  Integer pageSize) {
        List<DataSourceAuthorityOAApplyBean> lists = Lists.newArrayList();
        try {
            lists = dataSourceAuthDao.getBeanListsByMap(map, new RowBounds(pageNum, pageSize));
            if (lists != null && lists.size() > 0) {
                return lists;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public Page<DataSourceAuthorityOAApplyBean> getBeanListsByProjectGroup(List<String> projects, Integer pageNum,
                                                                           Integer pageSize) {
        Page<DataSourceAuthorityOAApplyBean> page;
        try {
            page = (Page<DataSourceAuthorityOAApplyBean>) dataSourceAuthDao.getBeanListsByProjectGroup(projects,
                new RowBounds(pageNum, pageSize));
            return page;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Page<DataSourceAuthorityOAApplyBean> getBeanAllLists(Integer pageNum, Integer pageSize) {
        Page<DataSourceAuthorityOAApplyBean> page ;
        try {
            page = (Page<DataSourceAuthorityOAApplyBean>) dataSourceAuthDao.getAllDataSource(new RowBounds(pageNum, pageSize));
            return page;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean deleteDatasourceById(Long id) {
        boolean flag = false;
        try {
            dataSourceAuthDao.deleteBeanById(id);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

}
